package com.daogu.fuelcard.controller;

import com.daogu.fuelcard.entity.OilCard;
import com.daogu.fuelcard.service.OilCardService;
import com.daogu.fuelcard.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author daogu
 */
@Controller
@Tag(name = "油卡控制器")
public class OilCardController {

    @Autowired
    private OilCardService oilCardService;

    @PostMapping("/updateBalance")
    @Operation(description = "修改卡号余额")
    @ResponseBody
    public Result<Void> updateBalance(@RequestParam("cardNo") String cardNo,@RequestParam("balance") BigDecimal balance) {
        return oilCardService.updateBalance(cardNo,balance);
    }
    @PostMapping("/CardDeleted")
    @Operation(description = "删除卡号")
    @ResponseBody
    public Result<Void> deletedById(@RequestParam("id") String id) {
        return oilCardService.deletedById(id);
    }

    @ResponseBody
    @Operation(description = "添加油卡")
    @PostMapping("/insertCard")
    public Result<Void> insert(@RequestBody @Validated OilCard oilCard) {
        return oilCardService.insert(oilCard);
    }

    @ResponseBody
    @Operation(description = "获取油卡列表")
    @GetMapping("/getOilCard")
    public Result<PageInfo<OilCard>> getOilCard(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return oilCardService.getOilCard(pageNum,pageSize);
    }

    @Operation(description = "油卡页面")
    @GetMapping("/OilCard")
    public String login() {
        return "OilCard";
    }


}
